package com.app.bimo.library_db.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.app.bimo.library_db.dao.AppDataDao;
import com.app.bimo.library_db.dao.BookDataDao;
import com.app.bimo.library_db.dao.BookRecordDao;
import com.app.bimo.library_db.dao.ChapterDataDao;
import com.app.bimo.library_db.dao.ChapterRecordDao;
import com.app.bimo.library_db.dao.DaoMaster;
import com.app.bimo.library_db.dao.FontTypeDataDao;
import com.app.bimo.library_db.dao.ReadDayRecordDao;
import com.app.bimo.library_db.dao.ReadTimeRecordDao;
import com.app.bimo.library_db.dao.SearchDataDao;
import com.app.bimo.library_db.dao.SearchHistoryDao;
import com.app.bimo.library_db.dao.UserDataDao;
import com.github.yuweiguocn.library.greendao.MigrationHelper;

import org.greenrobot.greendao.database.Database;

public class MySQLiteOpenHelper extends DaoMaster.OpenHelper {
    public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {

            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, BookDataDao.class, BookRecordDao.class, ChapterDataDao.class, FontTypeDataDao.class,
                ReadDayRecordDao.class, ReadTimeRecordDao.class, SearchDataDao.class, SearchHistoryDao.class,
                UserDataDao.class, ChapterRecordDao.class, AppDataDao.class);
    }
}